package com.cafe.pro.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.cafe.pro.dto.UserSaveDto;
import com.cafe.pro.dto.UserSearchRequest;
import com.cafe.pro.entity.User;
import com.cafe.pro.manager.KeyManager;
import com.cafe.pro.mapper.UserMapper;
import com.cafe.pro.util.CryptoUtils;
import com.cafe.pro.vo.UserVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@AllArgsConstructor
public class UserService {
    private final UserMapper userMapper;
    private final KeyManager keyManager;

    public List<UserVo> listUsers(UserSearchRequest request) throws Exception {
        log.info("查询用户-{}", JSONUtil.toJsonStr(request));
        return userMapper.queryUsers(request); // 查询所有用户
    }

    public boolean addUser(UserSaveDto user) {
        return userMapper.insert(BeanUtil.toBean(user, User.class)) > 0;
    }

    public UserVo getUserById(Integer id) {
        User user = userMapper.selectById(id);
        return BeanUtil.toBean(user, UserVo.class);
    }
}
